<template>
    <view class="bg-content">
        <u-sticky>
            <div style="border-bottom: 1rpx solid #eeeeee; height: 40px; background-color: #FFFFFF; padding-top: 4px;">
                <u-search placeholder="请输入搜索关键词" v-model="goodsListFilterParams.searchKeyword"
                          :disabled="true" @click="uni.navigateBack({delta: 1})" @custom="uni.navigateBack({delta: 1})"></u-search>
            </div>
        </u-sticky>

        <goodsList ref="goodsListRef" :goodsListFilterParams="goodsListFilterParams"
                   v-if="urlParams.type === '0' && goodsListFilterParams.searchKeyword"></goodsList>

        <tbStoreList ref="tbStoreListRef" :tbStoreListFilterParams="tbStoreListFilterParams"
                     v-if="urlParams.type === '1' && tbStoreListFilterParams.searchKeyword"></tbStoreList>
    </view>
</template>

<script>

    import goodsList from '@/components/goods-list.vue'
    import tbStoreList from '@/components/store-list.vue'

    export default {
        data() {
            return {
                goodsListFilterParams: {
                    searchKeyword: null,
                    storeClassId: null,
                    orderBy: 'salesvolume desc'
                },
                tbStoreListFilterParams: {
                    _timestamp: new Date().getTime(),
                    communityId: this.globalVariable.userInfo.tbCommunity.id,
                    searchKeyword: null,
                    storeClassId: null,
                    orderBy: 'coordinate desc'
                }
            }
        },
        components: {
            goodsList,
            tbStoreList,
        },
        onLoad(options) {
            console.log(options);
            if (this.urlParams.type === '0') {
                uni.setNavigationBarTitle({
                    title: '搜索商品结果'
                });
            } else if (this.urlParams.type === '1') {
                uni.setNavigationBarTitle({
                    title: '搜索店铺结果'
                });
            }
            this.goodsListFilterParams.searchKeyword = options.searchKeyword;
            this.tbStoreListFilterParams.searchKeyword = options.searchKeyword;
        },
        methods: {},
        created() {
        },
        // 上拉加载
        onReachBottom: function () {
            console.log(this.$refs.goodsListRef)
            if (this.urlParams.type === '0') {
                if (this.$refs.goodsListRef.pagination.hasNextPage) {
                    this.$refs.goodsListRef.doInfinite();
                }
            } else if (this.urlParams.type === '1') {
                if (this.$refs.tbStoreListRef.pagination.hasNextPage) {
                    this.$refs.tbStoreListRef.doInfinite();
                }
            }
        },
    }
</script>

<style lang="scss" scoped>
</style>
